<?php
/*
 * 会员管理
 */
class UserAction extends BusinessAction {

    public function index() {
    	$map = array();
    	if($_REQUEST['username']){
    		$map['username'] = $_REQUEST['username'];
    	}
        $U = M('user');
        import("@.ORG.Page");
        $count = $U->where($map)->count();
        $p = new Page($count, 20);
        $list = $U->where($map)->limit($p->firstRow . ',' . $p->listRows)->order('user_id desc')->select();
        $page = $p->show();

        $this->assign('page', $page);
        $this->assign('list', $list);
        $this->display();
    }

    public function admin_index() {
    	$Admin = M('Admin');
        import("@.ORG.Page");
        $count = $Admin->count();
        $p = new Page($count, 10);
        $list = $Admin->limit($p->firstRow . ',' . $p->listRows)->order('id desc')->select();
        $page = $p->show();
        $this->assign('page', $page);
        $this->assign('list', $list);
        $this->display();
    }
    
    public function edit_admin() {
    	$a = M('Admin');
    	$map['id'] = $_GET['id'];
    	$user = $a->where($map)->find();
    	if ($a) {
    		$this->assign('user', $user);
    		$this->display();
    	} else {
    		$this->error('不存在');
    	}
    }
    

    public function save_admin() {
    	$a = M('Admin');
    	if (!$a->create()) {
    		$this->error($a->getError());
    	} else {
    		$data['id'] = $a->id;
    		$data['email'] = $a->email;
    		if ($a->password != "")
    			$data['password'] = md5($a->password);
    		$result = $a->save($data);
    		if ($result) {
    			$this->success("修改成功!");
    		} else {
    			$this->error("修改失败!");
    		}
    	}
    }
    
    public function insert() {
        $Admin = D('Admin');
        if (!$Admin->create()) {
            $this->error($Admin->getError());
        } else {
            $Admin->create_time = time();
            if ($Admin->add()) {
                $this->success('添加成功');
            } else {
                $this->error("添加失败");
            }
        }
    }
}

?>
